using System.Collections;
using PetShop.Domain.Model;
using PetShop.Infrastructure.NHibernate;
using NHibernate;
using System.Collections.Generic;


namespace PetShop.Infrastructure.Gateways
{

	public class ItemGateway {

		private readonly ISession _session;

		public ItemGateway()
		{
			_session = NHibernateHttpModule.CurrentSession; 
		}

        public IEnumerable<ItemEntity> GetItemsByProduct(string productId)
		{
			
			IQuery query = _session.CreateQuery("SELECT p FROM ItemEntity as p WHERE p.Product = :Product");
			query.SetString("Product", productId);
            var itemsByProduct = query.Enumerable<ItemEntity>();
			return itemsByProduct;
		}

		public ItemEntity GetItemByID(string itemId) 
		{
			ItemEntity item = null;
			item = _session.Get<ItemEntity>(itemId);
			return item;
		}

		public void Update(ItemEntity item)
		{
			_session.Update(item);
		}

	}
}
